<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script>
			//WeakMap的使用API和Map一样
			const wm1 = new WeakMap(),
			      wm2 = new WeakMap(),
			      wm3 = new WeakMap();
			const o1 = {},
			      o2 = function(){},
			      o3 = window;
			
			wm1.set(o1, 37);
			wm1.set(o2, "azerty");
			wm2.set(o1, o2); // value可以是任意值,包括一个对象或一个函数
			wm2.set(o3, undefined);
			wm2.set(wm1, wm2); // 键和值可以是任意对象,甚至另外一个WeakMap对象
			
			console.log('azerty',wm1.get(o2)); // "azerty"
			console.log('undefined',wm2.get(o2)); // undefined,wm2中没有o2这个键
			console.log('undefined',wm2.get(o3)); // undefined,值就是undefined
			
			console.log('true',wm1.has(o2)); // true
			console.log('false',wm2.has(o2)); // false
			console.log('true',wm2.has(o3)); // true (即使值是undefined)
			
			wm3.set(o1, 37);
			console.log('37',wm3.get(o1)); // 37
			
			console.log('true',wm1.has(o1));   // true
			wm1.delete(o1);
			console.log('false',wm1.has(o1));   // false
		</script>
	</body>
</html>
